package com.example.homework_4_permission.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.example.homework_4_permission.mapper.UserMapper;
import com.example.homework_4_permission.pojo.Result;
import com.example.homework_4_permission.pojo.User;
import com.example.homework_4_permission.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Result login(User user) {
        User userInfo = userMapper.selectByUsernameAndPassword(user);
        if (!ObjectUtils.isEmpty(userInfo)) {
            StpUtil.login(userInfo.getUid());
            return Result.ok("登录成功", userInfo);
        }
        return Result.error("账号或密码错误!");
    }
}
